package com.bmft.controller;

import com.bmft.util.file.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 文件上传，文件下载还没有实现，到时候再说.
 * @author Jarvan
 * @version 1.0
 * @create 2020/12/6 14:48
 */
@RestController
@RequestMapping("/file/**")
public class FileController {

    @Autowired
    FileUtil fileUtil;

    @PostMapping("/upload")
    public String uploadFile(HttpServletRequest request) {
        //从request里面获得file
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        MultipartFile file = files.get(0);
        //上传
        fileUtil.createLocalFile("admin",file);
        return  "上传成功";

    }
}
